import { getUserId } from '@/utils/utils';
import { observable, action } from "mobx"
import { network } from "@/utils/network"
import Taro from '@tarojs/taro'

/**
 * 意见反馈model
 */
class AdviseModel {

  @observable
  content: string



  constructor() {
    this.content = ''
  }


  @action
  setValue(key, value) {
    this[key] = value;
  }

  async crete() {
    if (!this.content) {
      Taro.showToast({ icon: 'none', title: '内容不能为空' });
      return;
    }

    Taro.showLoading({ title: '加载中' })
    const params = {
      user_id: getUserId(),
      content: this.content
    }

    try {
      const { code } = await network.post('/wx/feedback', params);
      if (code === 0) {
        Taro.showToast({ icon: 'success', title: '反馈成功' });
        setTimeout(() => {
          Taro.switchTab({ url: '/pages/me/me/index' });
        }, 700);
      }
      Taro.hideLoading()
    } catch (error) {
      Taro.hideLoading()
    }
  }



}

export const adviseModel = new AdviseModel()
